<p>Unnecessary casting expressions make the code harder to read and understand.</p>
<h2>Noncompliant Code Example</h2>
<pre>
public void example() {
  for (Foo obj : (List&lt;Foo&gt;) getFoos()) {  // Noncompliant; cast unnecessary because List&lt;Foo&gt; is what's returned
    //...
  }
}

public List&lt;Foo&gt; getFoos() {
  return this.foos;
}
</pre>
<h2>Compliant Solution</h2>
<pre>
public void example() {
  for (Foo obj : getFoos()) {
    //...
  }
}

public List&lt;Foo&gt; getFoos() {
  return this.foos;
}
</pre>
<h2>Exceptions</h2>
<p>Casting may be required to distinguish the method to call in the case of overloading:</p>
<pre>
class A {}
class B extends A{}
class C {
  void fun(A a){}
  void fun(B b){}

  void foo() {
    B b = new B();
    fun(b);
    fun((A) b); //call the first method so cast is not redundant.
  }

}
</pre>

